package com.cmy.common.pojo;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;

/**
 * @Author:Cmy
 * @Date:2023-08-14 11:56
 */
public class DelayTask implements Delayed {

    private String name;

    private long executeTime;

    public DelayTask(String name, long delay) {
        this.name = name;
        this.executeTime = System.currentTimeMillis()+delay;
    }

    public String getName() {
        return name;
    }

    @Override
    public long getDelay(TimeUnit unit) {
        return unit.convert(executeTime-System.currentTimeMillis(),TimeUnit.MILLISECONDS);
    }

    @Override
    public int compareTo(Delayed o) {
        return Long.compare(getDelay(TimeUnit.MILLISECONDS),o.getDelay(TimeUnit.MILLISECONDS));
    }
}

    